package com.sky.utils;

public class UrlBuilder {
    private final StringBuilder urlBuilder;
    private boolean hasParams;

    public UrlBuilder(String baseUrl) {
        this.urlBuilder = new StringBuilder(baseUrl);
        this.hasParams = false;
    }

    public UrlBuilder addParam(String key, String value) {
        if (value != null && !value.isEmpty()) {
            if (!hasParams) {
                urlBuilder.append("?").append(key).append("=").append(value);
                hasParams = true;
            } else {
                urlBuilder.append("&").append(key).append("=").append(value);
            }
        }
        return this; // 允许链式调用
    }

    public String build() {
        return urlBuilder.toString();
    }
}
